﻿using System;
using System.Collections.Generic;
using System.Net.Sockets;

namespace Fadd.Remoting
{
	/// <summary>
	/// Creates remoting proxies for interfaces
	/// </summary>
    public class ProxyFactory
    {
        private readonly RemotingClient _client;
		//private Dictionary<Type, InterfaceProxy> _proxies = new Dictionary<Type, InterfaceProxy>();

        public ProxyFactory(IServiceResolver serviceResolver, string hostName, int port)
        {
        	Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        	socket.Connect(hostName, port);
            _client = new RemotingClient(serviceResolver, socket);
        }

        public object CreateProxy(Type type)
        {
        	return new InterfaceProxy(_client, type);
        }
    }
}
